Skip to content

Fix/fmt tfvars#373

Open
amincheloh wants to merge 2 commits into
boltops-tools:masterfrom
amincheloh:fix/fmt-tfvars
Open

Fix/fmt tfvars#373
amincheloh wants to merge 2 commits into
boltops-tools:masterfrom
amincheloh:fix/fmt-tfvars

Conversation

@amincheloh

Copy link
Copy Markdown
Contributor
  • I've added tests (if it's a bug, feature or enhancement)
  • I've adjusted the documentation (if it's a feature or enhancement)
  • The test suite passes (run bundle exec rspec to verify this)

Summary

terraspace fmt renames source files containing ERB (<%) to *.skip before running terraform fmt, then restores them. The skip glob only matched *.{tf,skip}, so ERB .tfvars files were missed. With -recursive, terraform fmt descends into the tfvars/ subfolder and errors on them:

Error: Invalid character on tfvars/base.tfvars line 1:
1: some_var = <%= output('other-stack.x') %>

Fix: add tfvars to the glob so ERB .tfvars files are skipped like ERB .tf files. Also documents the -recursive option in the fmt help text.

Context

terraform fmt is non-recursive by default, so .tfvars in tfvars/ are only reached with -recursive, where the missing skip handling surfaced as a hard error. One-line change in lib/terraspace/cli/fmt/runner.rb:

- **/*.{tf,skip}
+ **/*.{tf,tfvars,skip}

How to Test

With an ERB .tfvars in a stack's tfvars/ subfolder, terraspace fmt -recursive errors before this change (exit 2) and succeeds after (exit 0, ERB tfvars left intact). Specs:

bundle exec rspec spec/terraspace/cli/fmt/runner_spec.rb

Version Changes

Patch — backwards-compatible bug fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant